#! /usr/bin/env python
#coding=utf-8
import cv2
import os

cam=cv2.VideoCapture(0)
f_det=cv2.CascadeClassifier('include/haarcascade_frontalface_alt.xml')
f_id=input('enter user id:')
print('Now, capturing the face')
count=0
while True:
    success, img=cam.read() 
    gimg=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 
    f=f_det.detectMultiScale(gimg,1.3,5) 
    for (x,y,w,h) in f:         
        cv2.rectangle(gimg, (x,y), (x+w,y+h),(255,0,0))
        count += 1
        cv2.imwrite('face/' + str(f_id) + '.look_' + str(count) + '.jpg',
                    gimg[y:y + h, x:x + w])
    cv2.imshow('image', gimg)
    k = cv2.waitKey(100)
    if count >= 100:
        break
cam.release()
cv2.destroyAllWindows()


